/*
 * World.hpp
 *
 *  Created on: 27-12-2010
 *      Author: Przemek
 */

#pragma once

#include "Element.hpp"
#include "geometry/Rectangle.hpp"
#include "geometry/CircleSlice.hpp"
#include "pch.hpp"

/*
 * A singleton class which represents the whole world as a collection of Elements. The world can be either
 * stopped or running. When running, the time is calculated continuously - using floating point numbers.
 */
class World
{
	public:
		typedef std::vector<boost::shared_ptr<Element> > ElementsVector;
		static const geometry::Rectangle BOUNDS;

	private:
		bool running;
		ElementsVector elements;
		ElementsVector scheduledToAdd;

	public:
		static World& getInstance();
		void updateWithDeltaTime(int timeSpeedMultiplication, float deltaTimeInSeconds);
		const ElementsVector& getElements() const;
		// get only these elements which are in circleSlice
		const ElementsVector getElements(const CircleSlice& circleSlice) const;
		ElementsVector getNeighborhoodBarriers(const Vector& position);
		bool isRunning() const;
		void setRunning(bool running);
		void add(Element* element);
		void add(boost::shared_ptr<Element>& element);
		void remove(Element* element);
		// schedule to add new element at the end of update
		void scheduleToAdd(Element* element);
		Element* getElementAt(const Vector& point);
		// checks if colliding with other world element
		bool canPlaceAt(const geometry::Rectangle& rectangle) const;

	private:
		World();
		World(const World& other);
		World& operator=(const World& other);

		void updateElements(float deltaTimeInSeconds);
		void growPlantsRandomly();
		void spreadWater();
};
